package com.springboot.common.entity;

/**
 * 响应数据封装对象
 */
public class ResponseResult {
 
    /**
     * 错误信息
     */
    private String msg="";

    /**
     * 状态信息
     */
    private int code = 0 ;
    /**
     * 数据
     */
    private Object data;

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public ResponseResult(ResponseStatus status, Object data) {
        this.msg = status.getMessage();
        this.code = status.getCode();
        this.data = data;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    /**
     * 返回成功对象
     * @param data
     * @return
     */
    public static   ResponseResult ok(Object data){
        return new ResponseResult(ResponseStatus.OK, data);
    }
 
    /**
     * 返回错误对象
     * @param status
     * @return
     */
    public static ResponseResult error(ResponseStatus status){
        return new ResponseResult(status,"");
    }
    public static ResponseResult error(String msg){
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode(ResponseStatus.NORMAL_ERROR.getCode());
        responseResult.setMsg(msg);
        responseResult.setData("");
        return responseResult;
    }
    ResponseResult(){

    }
    /**
     * 返回错误对象
     * @param status
     * @return
     */
    public static ResponseResult error(ResponseStatus status, String msg){
        return new ResponseResult(status,msg);
    }
 
}